//
//  ViewController.m
//  Animation
//
//  Created by yxl on 2022/4/6.
//

#import "ViewController.h"
#import "CALayer+Category.h"

@interface ViewController ()
@property (nonatomic, weak) UIView *v;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIView *v = [[UIView alloc] init];
    v.frame = CGRectMake(0, 0, 100, 100);
    v.center = self.view.center;
    v.backgroundColor = [UIColor redColor];
    [self.view addSubview:v];
    self.v = v;
    
    UIButton *a = [UIButton buttonWithType:UIButtonTypeSystem];
    a.frame = CGRectMake(v.frame.origin.x, CGRectGetMaxY(v.frame) + 30, 50, 30);
    [a setTitle:@"旋转" forState:UIControlStateNormal];
    [a addTarget:self action:@selector(aClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:a];
    
    UIButton *b = [UIButton buttonWithType:UIButtonTypeSystem];
    b.frame = CGRectMake(v.frame.origin.x, CGRectGetMaxY(a.frame) + 30, 50, 30);
    [b setTitle:@"暂停" forState:UIControlStateNormal];
    [b addTarget:self action:@selector(bClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:b];
    
    UIButton *c = [UIButton buttonWithType:UIButtonTypeSystem];
    c.frame = CGRectMake(v.frame.origin.x, CGRectGetMaxY(b.frame) + 30, 50, 30);
    [c setTitle:@"继续" forState:UIControlStateNormal];
    [c addTarget:self action:@selector(cClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:c];
    
}

// 旋转
- (void)aClick{
    [CALayer makeAnimation:self.v];
}

// 暂停
- (void)bClick{
    [CALayer pauseLayer:self.v.layer];
}

// 继续
- (void)cClick{
    [CALayer resumeLayer:self.v.layer];
}

@end
